package com.rjpacket.chileme.app.adapters;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.rjpacket.chileme.app.WebActivity;
import com.rjpacket.chileme.app.models.MainHeadUp;
import com.rjpacket.chileme.app.tasks.ImageLoader;

import java.util.List;

/**
 * Created by Administrator on 2015/3/23 0023.
 */
public class ViewPagerCommonAdapter extends PagerAdapter{

    public void setEnterViewPager(View.OnClickListener enterViewPager) {
        this.enterViewPager = enterViewPager;
    }

    private View.OnClickListener enterViewPager;
    //上下文
    private Context context;
    //存储图片的url集合
    private List<MainHeadUp> list;

    private View.OnClickListener listener;

    public ViewPagerCommonAdapter(Context context, List<MainHeadUp> list) {
        this.context = context;
        this.list = list;
    }



    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object o) {
        return view == o;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        //代码写一个ImageView
        ImageView ret = new ImageView(context);

        ret.setTag(position);

        ret.setOnClickListener(enterViewPager);

        //获得每张图片的url
        String url = list.get(position).getImgUrl();
        //下载图片
        ImageLoader loader = new ImageLoader(ret);

        loader.execute(url);

        return ret;
    }
}
